<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$settings=$this->plugin_setting('setting');
$return=array();
cfc('core')->checklogin();
$return['member']=array();
if($_RQ['op']=='list'){
	$return['list']=pdo_getall('jy_cxjxiche_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>'6'),'','','createtime desc');
	foreach($return['list'] as &$v){
		$v['createtime']=date('Y-m-d H:i:s',$v['createtime']);
	}
	exi($return);
}
if($_RQ['op']=='list'){
	$post=get_postdata();
	$order=pdo_get('jy_cxjxiche_order',array('id'=>$post['id']));
	$order['lat']=json_decode($order['lat'],true);
	$mid=$order['mid'];
	$worker=pdo_get('jy_cxjxiche_worker',array('mid'=>$_SESSION['uid']));
	$worker['lat']=json_decode($worker['lat'],true);
	$jjuli=cfc('tools')->getdistance($order['lat']['lng'],$order['lat']['lat'],$worker['lat']['lng'],$worker['lat']['lat']);
	$jjuli=intval($jjuli/1000);
	if(intval($settings['jkjuli']) < $jjuli){
		$price2=($jjuli-$settings['jkjuli'])*$settings['price2'];
	}else{
		$price2=0;
	}
	$price=$price2+$order['price1'];
	pdo_update('jy_cxjxiche_order',array('worker_id'=>$worker['id'],'jjuli'=>$jjuli,'price2'=>$price2,'price'=>$price,'status'=>1,'worker_id'=>$worker['id']),array('id'=>$post['order']));
	$setting=core_setting('cloud');//获取云洗车参数
	//生成前端签名
	$sign=sha1(TIMESTAMP.$setting['cloudkey'].$_SESSION['uniacid'].$_SESSION['uid'].$setting['secret']);
	//拼接前端发送消息的前缀
	$message_pre1=$sign.';'.TIMESTAMP.';'.$setting['cloudkey'].';'.$_SESSION['uniacid'].';'.$_SESSION['uid'].';';
	$m=array('name'=>$worker['name'],'mobile'=>$worker['mobile'],'price'=>$price,'price1'=>$order['price1'],'jjuli'=>$jjuli,'price2'=>$price2);
	$message=json_encode($m);
	$post2=array(
		'message'=>$message_pre1.$mid.';'.$message,
	);
	cloud_request('cloud.forward',$post2);
	exi('已接单','','jy_cxjxiche/daohang/main/orderid='.$post['id']);
}
?>